Skip to content

Conversation

@sjorsdonkers
Copy link
Contributor

Initial implementation of 2 interfaces of performance
https://developer.mozilla.org/en-US/docs/Web/API/Performance/timeOrigin
https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
many still TODO

Performance implementation as part of Window, WorkerGlobalScope not implemented.

These APIs are implemented as part of making Playwright click work.

@sjorsdonkers sjorsdonkers requested a review from karlseguin May 13, 2025 14:17
// Monotonically increasing
var now = perf._now();
while (now <= 0) { // Loop for now to not be 0
try testing.expectEqual(now, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameters are swapped, it's expected, actual /shrug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll take this change into the next PR

}

pub fn get_timeOrigin(self: *const Performance) f64 {
const is_posix = switch (@import("builtin").os.tag) { // From std.time.zig L125
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine, but just FYI, build.zig blocks any builds that aren't on linux or macos. There are a few places, like browser.zig timestamp function, which treat anything else as unreachable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, this is ugly. I wanted to just use the is_posix constant in time.zig, but that is not pub for some reason.
Then wanted to just check if @TypeOf(std.time.Instant.timestamp) == i64 but also:

        const ts_field = @typeInfo(std.time.Instant).@"struct".fields[0];
        if (!std.mem.eql(u8, ts_field.name, "timestamp")) @compileError(ts_field.name);
        const is_i64 = ts_field.type == i64;

Does not seem to work ..

@karlseguin
Copy link
Collaborator

LGTM

@sjorsdonkers sjorsdonkers merged commit 54c2ded into main May 13, 2025
9 checks passed
@sjorsdonkers sjorsdonkers deleted the performance_now branch May 13, 2025 15:42
@github-actions github-actions bot locked and limited conversation to collaborators May 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants